<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>{{ .title }}</title>
    <link rel="stylesheet" href="//unpkg.com/layui@2.6.8/dist/css/layui.css">
    <link rel="stylesheet" href="../static/css/common.css">
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo layui-hide-xs layui-bg-black">{{ .title }}</div>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item layui-hide layui-show-md-inline-block">
                <a>
                    {{ .nickname }}
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="/admin/loginOut">退出登录</a></dd>
                </dl>
            </li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="left-menu">

                {{ range .leftMenu }}
                    <li class="layui-nav-item" menu-id="{{ .ID }}" menu-title="{{ .Title }}" menu-link="{{ .Link }}">
                        {{ if len .Child }}
                            <a>{{ .Title }}</a>
                        {{else}}
                            <a onclick="TabAdd({{.ID}}, {{.Title}}, {{.Link}})">{{ .Title }}</a>
                        {{end}}
                        {{ if len .Child }}
                            <dl class="layui-nav-child">
                                {{ range .Child }}
                                <dd menu-id="{{ .ID }}" menu-title="{{ .Title }}" menu-link="{{ .Link }}"><a onclick="TabAdd({{.ID}}, {{.Title}}, {{.Link}})">{{ .Title }}</a></dd>
                                {{ end }}
                            </dl>
                        {{end}}
                    </li>
                {{ end }}
            </ul>
        </div>
    </div>

    <div class="layui-body">
        <div class="layui-tab" style="height: 100%" lay-filter="body" lay-allowClose="true">
            <ul class="layui-tab-title">
            </ul>
            <div class="layui-tab-content" style="height: calc(100% - 41px);">
            </div>
        </div>
    </div>

    <div class="layui-footer">
        {{ .footText }}
    </div>
</div>
<script src="//unpkg.com/layui@2.6.8/dist/layui.js"></script>
<script>
    //JS
    layui.use(['element', 'layer', 'util'], function () {
        var element = layui.element
            , layer = layui.layer
            , util = layui.util
            , $ = layui.$;

        window.TabAdd = function (id, title, link) {
            // 如果窗口已经打开直接切换过去
            if ($("[lay-filter$='body'] [lay-id$="+id+"]").length > 0) {
                element.tabChange('body', id)
                return
            }
            var content = '<iframe src="'+link+'" frameborder="0" scrolling="auto" width="100%" height="100%" ></iframe>';
            element.tabAdd('body', {
                title: title
                ,content: content
                ,id: id
            });
            $("[lay-filter$='body'] .layui-tab-item").addClass("layui-tab-item-height")
            element.tabChange('body', id)
        }

        // 打开tab同时左侧菜单显示对应模块，id为一级菜单id
        function openTabWithMenu(id) {
            var levelOne = $("[lay-filter$='left-menu'] [menu-id$='"+id+"']");
            if (!levelOne) {
                return
            }
            var realId;
            var title;
            var link;
            if (levelOne.children("dl").length>0) {// 有子菜单
                levelOne.children("dl").children("dd:first").addClass("layui-this")
                levelOne.addClass("layui-nav-itemed")
                realId = levelOne.children("dl").children("dd:first").attr("menu-id")
                title = levelOne.children("dl").children("dd:first").attr("menu-title")
                link = levelOne.children("dl").children("dd:first").attr("menu-link")
            } else {// 无子菜单
                levelOne.addClass("layui-this")
                levelOne.addClass("layui-nav-itemed")
                realId = levelOne.attr("menu-id")
                title = levelOne.attr("menu-title")
                link = levelOne.attr("menu-link")
            }
            TabAdd(realId, title, link)
        }
        // 默认打开一个菜单
        openTabWithMenu({{ .defaultOpenParentId }})
    });

</script>
</body>
</html>